<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="账单" prop="billNum">
        <el-input
          v-model="queryParams.billNum"
          placeholder="请输入账单"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['energy:sfReceiptDetail:export']"
        >导出</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="sfReceiptDetailList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="账单" align="center" prop="billNum" />
      <el-table-column label="费用类型" align="center" prop="feeTypeName" />
      <el-table-column label="收款账户" align="center" prop="receiptAccount" />
      <el-table-column label="收款账号" align="center" prop="receiptAccountNum" width="200px"/>
      <el-table-column label="账单金额" align="center" prop="receiptAmount" />
      <el-table-column label="违约金" align="center" prop="receiptTotalFine" />
      <el-table-column label="收款时间" align="center" prop="receiptTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.receiptTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="到账时间" align="center" prop="arrivalTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.arrivalTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />

    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改收款明细对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="账单Id" prop="billId">
          <el-input v-model="form.billId" placeholder="请输入账单Id" />
        </el-form-item>
        <el-form-item label="收款方式" prop="receiptMethod">
          <el-input v-model="form.receiptMethod" placeholder="请输入收款方式" />
        </el-form-item>
        <el-form-item label="收款金额" prop="receiptAmount">
          <el-input v-model="form.receiptAmount" placeholder="请输入收款金额" />
        </el-form-item>
        <el-form-item label="收款时间" prop="receiptTime">
          <el-date-picker clearable size="small"
            v-model="form.receiptTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择收款时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="到账时间" prop="arrivalTime">
          <el-date-picker clearable size="small"
            v-model="form.arrivalTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择到账时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="删除标志(0正常 1删除)" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入删除标志(0正常 1删除)" />
        </el-form-item>
        <el-form-item label="租户Id" prop="tenantId">
          <el-input v-model="form.tenantId" placeholder="请输入租户Id" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listSfReceiptDetail, getSfReceiptDetail, delSfReceiptDetail, addSfReceiptDetail, updateSfReceiptDetail } from "@/api/smartParks/operatingFee/operatingFeePayment";

export default {
  name: "FeeApartmentDetail",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 收款明细表格数据
      sfReceiptDetailList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        billNum: null,
        billType:'公寓账单',
        receiptMethod: null,
        receiptAmount: null,
        receiptTime: null,
        arrivalTime: null,
        tenantId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        delFlag: [
          { required: true, message: "删除标志(0正常 1删除)不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
  },
    beforeRouteEnter(to, from, next) {
    if (to.query.id && from.name === "FeeApartment" ) {
      next((vm) => {
        vm.queryParams.billId = to.query.id;
        vm.getList();
      });
    } else {
      next((vm) => {
        vm.queryParams.billId = "";
        vm.queryParams.billNum = "";
        vm.getList();
      });
    }
    next()
  },
  methods: {
    /** 查询收款明细列表 */
    getList() {
      this.loading = true;
      listSfReceiptDetail(this.queryParams).then(response => {
        this.sfReceiptDetailList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        billId: null,
        receiptMethod: null,
        receiptAmount: null,
        receiptTime: null,
        arrivalTime: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        delFlag: null,
        tenantId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加收款明细";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getSfReceiptDetail(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改收款明细";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateSfReceiptDetail(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addSfReceiptDetail(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除收款明细编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delSfReceiptDetail(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('energy/sfReceiptDetail/export', {
        ...this.queryParams
      }, `energy_sfReceiptDetail.xlsx`)
    }
  }
};
</script>
